package top.vanchor.myblog2back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import top.vanchor.myblog2back.entity.BlogSubscribe;
import top.vanchor.myblog2back.mapper.BlogSubscribeMapper;
import top.vanchor.myblog2back.service.IBlogSubscribeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ding
 * @since 2021-11-12
 */
@Service
public class BlogSubscribeServiceImpl extends ServiceImpl<BlogSubscribeMapper, BlogSubscribe> implements IBlogSubscribeService {

    @Resource
    BlogSubscribeMapper blogSubscribeMapper;

    @Override
    public Integer toStarUser(Integer handleId, Integer targetId) {
        BlogSubscribe blogSubscribe = new BlogSubscribe();
        blogSubscribe.setSubUserId(handleId);
        blogSubscribe.setSubUserPid(targetId);
        return blogSubscribeMapper.insert(blogSubscribe);
    }

    @Override
    public Integer toUnStarUser(Integer handleId, Integer targetId) {
        QueryWrapper<BlogSubscribe> wrapper = new QueryWrapper<>();
        wrapper.eq("sub_user_id",handleId);
        wrapper.eq("sub_user_pid",targetId);
        return blogSubscribeMapper.delete(wrapper);
    }

    @Override
    public List<Integer> getStarIdsByUserId(Integer userId) {
        return blogSubscribeMapper.getStarIdsByUserId(userId);
    }
}
